
$(document).ajaxSend(function(event,xhr,options){
    let token = localStorage.getItem("user_token");
    xhr.setRequestHeader("user_header_token",token)
});



$(document).ajaxError(function(event,xhr,options,exc) {
    if(xhr.status==401) {
        alert("用户未登录,请先登录！");
        location.href = "blog_login.html";
    }else if(xhr.status==404){

    }else if(xhr.status==500) {

    }
});


function getUserInfo(url) {
    $.ajax({
        url: url,
        type: "get",
        success: function(result) {
            if(result.code == 200 && result != null && result.data != null) {
                let userInfo = result.data;
                $(".card h3").text(userInfo.userName);
                $(".card a").attr("href",userInfo.githubUrl);
            }
        }
    });
}



function logout() {
    let logout = confirm("确定是否退出");
    if(logout) {
        localStorage.removeItem("user_token");
        localStorage.removeItem("login_user_id");
        location.href = "blog_login.html";
    }
}